/*
 * Copyright (C) 2009 Ionut Dediu <deionut@yahoo.com>
 *
 * Licensed under the GNU General Public License Version 2
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

// SmartCamSettingsView.cpp

#include <coemain.h>
#include <aknutils.h>
#include <SmartCam_0xE696FBC9.rsg>

#include "SmartCamSettingsView.h"
#include "SmartCamSettingsContainer.h"
#include "SmartCamConst.h"
#include "SmartCamAppUi.h"

CSmartCamSettingsView* CSmartCamSettingsView::NewL(CSmartCamSettingsData& aSettingsData)
	{
	CSmartCamSettingsView* self = new (ELeave) CSmartCamSettingsView(aSettingsData);
	self->ConstructL();
	return self;
	}

void CSmartCamSettingsView::ConstructL()
	{
    BaseConstructL(R_SMARTCAM_SETTINGS_VIEW);
	}

CSmartCamSettingsView::CSmartCamSettingsView(CSmartCamSettingsData& aSettingsData):
	iContainer(NULL),
	iSettingsData(aSettingsData)
	{
	}

CSmartCamSettingsView::~CSmartCamSettingsView()
	{
    if(iContainer)
        {
        AppUi()->RemoveFromStack(iContainer);
        delete iContainer;
        iContainer = NULL;
        }
	}

TUid CSmartCamSettingsView::Id() const
    {
    return KUidSettingsView;
    }

void CSmartCamSettingsView::HandleCommandL(TInt aCommand)
    {
    if(aCommand == EAknSoftkeyOk)
    	((CSmartCamAppUi*)AppUi())->HandleSettingsChange();
    AppUi()->ActivateLocalViewL(KUidViewFinderView);
    }

void CSmartCamSettingsView::DoActivateL( const TVwsViewId& /* aPrevViewId */,
                                        TUid /*aCustomMessageId*/,
                                        const TDesC8& /*aCustomMessage*/ )
    {
    if(!iContainer)
    	{
	    iContainer = CSmartCamSettingsContainer::NewL(iSettingsData);
	    iContainer->SetMopParent(this);
	    AppUi()->AddToStackL(*this, iContainer);
	    iContainer->ActivateL();
    	}
    }

void CSmartCamSettingsView::DoDeactivate()
    {
    if(iContainer)
        {
        AppUi()->RemoveFromStack(iContainer);
        delete iContainer;
        iContainer = NULL;
        }
    }

void CSmartCamSettingsView::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane* aMenuPane)
    {
    static_cast<CSmartCamAppUi*> (CEikonEnv::Static()->EikAppUi())->DynInitMenuPaneL(aResourceId, aMenuPane);
    }

void CSmartCamSettingsView::HandleSizeChange()
    {
    if(iContainer)
	    {
		TRect mainPaneRect;
     	AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect);
     	iContainer->SetRect(mainPaneRect);
        }
    }

